package com.xjcs.notetools.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.ListFragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.xjcs.notetools.bean.MainNavigationBean
import com.xjcs.notetools.bean.MainNavigationType

class VpFragmentAdapter(private val navigationList: MutableList<MainNavigationBean>, fm: FragmentActivity): FragmentStateAdapter(fm){
    override fun getItemCount(): Int {
        return navigationList.size
    }

    override fun createFragment(position: Int): Fragment {
        return when(navigationList[position].type){
            MainNavigationType.LIST -> {
                ListFragment()
            }
            MainNavigationType.HABIT -> {
                ListFragment()
            }
            MainNavigationType.FOCUS -> {
                ListFragment()
            }
            MainNavigationType.MEMO -> {
                ListFragment()
            }
            MainNavigationType.MINE -> {
                ListFragment()
            }
        }
    }

    override fun getItemId(position: Int): Long {
        return navigationList[position].type.ordinal.toLong()
    }

    override fun containsItem(itemId: Long): Boolean {
        navigationList.forEach {
            if(itemId == it.type.ordinal.toLong()){
                return true
            }
        }
        return false
    }

}